<template>
  <div class="container">
  <MySearch @parentsearch='parentsearch' />
  <MyTable :myarr='arr' @resetTable='inithome' @openDialog ='parentopenDialog' />
  <MyPage :total='total' @changepage ="parentpage"   />
  <Dialog v-if='show' @closedialog='show = false' :arr='arrmap' @resettable='resettable'></Dialog>
  </div>
</template>
<script>
 import MyPage from './components/MyPage.vue'
 import MyTable from './components/MyTable.vue'
 import MySearch from './components/MySearch.vue'
 import { getLessonApi } from '../../api/studentApi'
 import Dialog from './components/Dialog'
export default {
    data(){
        return{
            arr:[],
            arrmap:[],
            keyword:'',
            page:1,
            pageSize:8,
            total:0,
            show:false
        }
    },
        components:{
            MyPage,
            MyTable,
            MySearch,
            Dialog
        },
        mounted(){
            this.inithome();
        },
        methods:{
            inithome(){
            var params= { keyword:this.keyword ,page : this.page , pageSize : this.pageSize};
                // console.log(this.arr); 
            getLessonApi(params).then(res=>{
                // console.log(res);
                   if(res.code == 200){
                        this.arr = res.data
                        this.total = res.total
                    }
                })
            },
            parentsearch(val){
                // console.log(val);
                this.keyword = val
                this.inithome();
            
            },
            parentpage(val){
                this.page = val
                this.inithome()
            },
            parentopenDialog(val){
                this.show = true;
                // console.log(this.arr);
               console.log(val);
                var arrm = []
                arrm = this.arr.map(item=> {
                    if (item.id.indexOf(val) != -1){
                       return this.arrmap = item
                    }
                } )
            
            },
            resettable(){
                this.inithome()
                this.show = false
            },
        }
}
</script>

<style scoped>

</style>